<?php

namespace App\Remote\AMap\Track;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class TraceRemote extends Remote
{
    /**
     * @param int $sid
     * @param int $tid
     * @param string $traceName
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function add(int $sid, int $tid, string $traceName)
    {
        return self::customRequestV3(
            "/v1/track/trace/add?" . http_build_query(self::withCommonHttpQueryParams()),
            RequestAlias::METHOD_POST,
            [
                "sid"    => $sid,
                "tid"    => $tid,
                "trname" => $traceName
            ],
            [
                'Content-Type' => 'application/x-www-form-urlencoded'
            ]
        );
    }

    /**
     * @param int $sid
     * @param int $tid
     * @param int $trId
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function delete(int $sid, int $tid, int $trId)
    {
        return self::customRequestV3(
            "/v1/track/trace/delete?" . http_build_query(self::withCommonHttpQueryParams()),
            RequestAlias::METHOD_POST,
            [
                "sid"  => $sid,
                "tid"  => $tid,
                "trid" => $trId
            ],
            [
                'Content-Type' => 'application/x-www-form-urlencoded'
            ]
        );
    }

    /**
     * @param int $sid
     * @param int $tid
     * @param int $trid
     * @param array $points
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function pointUpload(int $sid, int $tid, int $trid, array $points)
    {
        return self::customRequestV3(
            "/v1/track/point/upload?" . http_build_query(self::withCommonHttpQueryParams()),
            RequestAlias::METHOD_POST,
            [
                "sid"    => $sid,
                "tid"    => $tid,
                "trid"   => $trid,
                "points" => $points
            ],
            [
                'Content-Type' => 'application/json'
            ]
        );
    }
}
